<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/backstage/cl/common/wechatLibs.jsp"%>
<!doctype html>
<html>
<head>
    <title>已拆礼包</title>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    
</head>
<body>
   
    <div class="my-project-list">
        <div class="aui-tab" id="tab">
            <div class="aui-tab-item aui-active"><span>未使用</span></div>
            <!-- <div class="aui-tab-item"><span>已使用</span></div>
            <div class="aui-tab-item"><span>已过期</span></div> -->
        </div>
        <div class="box" id="box">
        <input type="hidden" id="page" value="1" />
            <ul id="project_list">
            </ul>
        </div>
  
         <div class="null-page" id="noProject" style="display:none">
            <img src="/bsc/js/wechat/images/none-gift.png">
            <span>您还没有项目哦~</span>
        </div>
    </div>
    <!-- 底部菜单 -->
    <div class="h88 mt20"></div>
    <div class="bottom-nav">
        <ul>
         
            <li class="find-project">
            <a href="/bsc/wechat/findProject" >
                <i class="ico"></i>
                <span>找项目</span>
             </a>
                
            </li>
          
           
            <li class="find-gift">
             <a href="/bsc/wechat/bagList" >
                <i class="ico"></i>
                <span>找礼包</span>
               </a> 
            </li>
           
            
            <li class="mine">
            <a href="/bsc/wechat/Gohome" >
                <i class="ico"></i>
                <span>我的</span>
                </a>
            </li>
            
        </ul>
    </div>
</body>
<script type="text/javascript" src="/bsc/js/wechat/js/aui-tab.js" ></script>
<script src="/bsc/js/wechat/js/aui-pull-refresh.js"></script>
<script type="text/javascript">
var toast = new auiToast();
var index=1;
var tab = new auiTab({
	element : document.getElementById("tab"),
	index : 1,
	repeatClick : false
}, function(ret) {
	 index=ret.index;
	 
	 doSearch(index,'0');
});
//页面初始化 
$(function() {
	doSearch(1,'0');
})
function doSearch(index,clearStatus) {
	toast.loading({
		title : "数据加载中",
		duration : 2000
	})
	$.ajax({
		type : 'post',
		url : '/bsc/wechat/GoProject',
		dataType : 'json',
		success : function(data) {
			if (data) {
				if(index==1){
					createOneList(data)
				}else if(index==2){
					createTwoList(data)
				}else{
					createThreeList(data)
				}
				
			} else {
				toast.fail({
					title : "查询失败",
					duration : 2000
				});
			}
			toast.hide();
		},
		error : function() {
			toast.fail({
				title : "网络异常",
				duration : 2000
			});
			toast.hide();
		}
	})
}
 //写一个方法，将秒数专为天数
function fun(){
 var s = second % 60; // 秒
 alert(s);
 var mi = (second - s) / 60 % 60; // 分钟
 var h = ((second - s) / 60 - mi ) / 60 % 24; // 小时
 var d = (((second - s) / 60 - mi ) / 60 - h ) / 24 // 天
}
var second;
//创建列表数据
function createOneList(data) {
	var recordList = $("#project_list");
		 $("#box").show();
		 $("#noProject").hide();
		 var html = '';
		 html = recordList.html();
		 for (var i = 0; i < data.length; i++) {
				var row=data[i];
				var use_time=row.bis_nurse_bag.soldout_time;
				var time=new Date(use_time).toLocaleDateString();
				/* second = row.use_time/1000; // 剩余秒数
				// 写一个方法，将秒数专为天数
				  var s = second % 60; // 秒
				 var mi = (second - s) / 60 % 60; // 分钟
				 var h = ((second - s) / 60 - mi ) / 60 % 24; // 小时
				 var d = (((second - s) / 60 - mi ) / 60 - h ) / 24 // 天 
				// fun(); */
				html += '<li onclick="showProjectDetail('+row.bag_id+')">';
				html += '<img class="fl" src="/bsc'+row.bis_nurse_bag.cover_photo+'">';
				html += '<div class="intro fl">';
				html += '  <h3>'+row.bis_nurse_bag.bag_name+'</h3>';
				html += '  <p id="ss">有效期至：'+time+'</p>';
				html += '</div>';
				html += ' <div class="state">';
				html += '<span>未使用</span>';
				html += ' </div>';
			}
		 recordList.html(html);
		//然后写一个定时器
		/*  window.setInterval(function(){
		  second --;
		document.getElementById("ss").innerHTML = createOneList(data);
		
		 }, 1000); */
	  }
	
function createTwoList(data) {
	var recordList = $("#project_list");
	
		 $("#box").show();
		 $("#noProject").hide();
		 var html = '';
				html = recordList.html();
		 for (var i = 0; i < data.length; i++) {
				var row=data[i];
				var use_time=row.bis_nurse_bag.overdue_time;
				var time=new Date(use_time).toLocaleDateString();
				/* var second = row.use_time / 1000; // 剩余秒数
				// 写一个方法，将秒数专为天数
				 var s = second % 60; // 秒
				 var mi = (second - s) / 60 % 60; // 分钟
				 var h = ((second - s) / 60 - mi ) / 60 % 24; // 小时
				 var d = (((second - s) / 60 - mi ) / 60 - h ) / 24 // 天 */
				html += '<li onclick="showProjectDetail('+row.bag_id+')">';
				html += '<img class="fl" src="/bsc'+row.bis_nurse_bag.cover_photo+'">';
				html += '<div class="intro fl">';
				html += '  <h3>'+row.bis_nurse_bag.project_name+'</h3>';
				html += '  <p>有效期至：' + time + '</p>';
				html += '</div>';
				html += ' <div class="state">';
				html += '<span>已使用</span>';
				html += ' </div>';
			
			}
	recordList.html(html);
	
}
//创建列表数据
function createThreeList(data) {
	var recordList = $("#project_list");
		 $("#box").show();
		 $("#noProject").hide();
		 var html = '';
				html = recordList.html();
		 for (var i = 0; i < data.length; i++) {
				var row=data[i];
				var use_time=row.bis_nurse_bag.overdue_time;
				var time=new Date(use_time).toLocaleDateString();
				/* var second = row.use_time / 1000; // 剩余秒数
				// 写一个方法，将秒数专为天数
				 var s = second % 60; // 秒
				 var mi = (second - s) / 60 % 60; // 分钟
				 var h = ((second - s) / 60 - mi ) / 60 % 24; // 小时
				 var d = (((second - s) / 60 - mi ) / 60 - h ) / 24 // 天 */
				html += '<li onclick="showProjectDetail('+row.bag_id+')">';
				html += '<img class="fl" src="/bsc'+row.bis_nurse_bag.cover_photo+'">';
				html += '<div class="intro fl">';
				html += '  <h3>'+row.bis_nurse_bag.bag_name+'</h3>';
				html += '  <p>有效期至：' + time + '</p>';
				html += '</div>';
				html += ' <div class="state">';
				html += '<span>已过期</span>';
				html += ' </div>';
			
			}
		 recordList.html(html);
	
}

function showProjectDetail(bag_id){
	alert(bag_id);
	 window.location.href = '/bsc/wechat/GoshowBagDetail?bag_id='+ bag_id;
}
</script>
</html>